using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using Spacejock;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Threading;
using yW5Lib;

namespace yWriter6
{
	public class clsPrintSummary
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintSummary(clsProject cProject)
		{
			//Discarded unreachable code: IL_057d, IL_0594, IL_059f, IL_05af, IL_06e5, IL_06e7, IL_06fb, IL_071d
			int num = default(int);
			int num4 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				int num3 = 1;
				num2 = 3;
				if (cProject.ChapterCount != 0)
				{
					num2 = 5;
					frmPickChapters frmPickChapters = new frmPickChapters(ref cProject);
					num2 = 6;
					frmPickChapters.EnableTagFilter();
					num2 = 7;
					frmPickChapters.EnableVPFilter();
					num2 = 8;
					frmPickChapters.ShowDialog();
					num2 = 9;
					if (!frmPickChapters.Cancelled)
					{
						num2 = 10;
						clsCollection<int> pickedIDs = frmPickChapters.PickedIDs;
						num2 = 11;
						clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "Summary of " + cProject.Title);
						num2 = 12;
						string left = "";
						num2 = 13;
						clsShared.cSubs.BusyMouse();
						num2 = 14;
						clsReport.AddTitle();
						num2 = 15;
						if (!frmPickChapters.WithUnused)
						{
							num2 = 16;
							clsReport.AddCentered("Does not include any scenes or chapters marked as 'Unused'");
						}
						num2 = 17;
						if (frmPickChapters.VPID > 0)
						{
							num2 = 18;
							clsReport.AddCentered("Only includes scenes with '" + cProject.get_CharByID(frmPickChapters.VPID).Title + "' as viewpoint character");
						}
						num2 = 19;
						if (Operators.CompareString(frmPickChapters.Tags.Trim(), "", TextCompare: false) != 0)
						{
							num2 = 20;
							clsReport.AddCentered("Only includes scenes tagged with '" + frmPickChapters.Tags + "'");
						}
						num2 = 21;
						clsReport.AddBR(2);
						num2 = 22;
						clsReport.OpenTable("cellpadding=2");
						num2 = 23;
						clsReport.OpenRow();
						num2 = 24;
						clsReport.AddCell(clsReport.Bold(clsShared.cLang.GetTranslation("Chapter")), "valign=top");
						num2 = 25;
						clsReport.AddCell(clsReport.Bold(clsShared.cLang.GetTranslation("Viewpoint")), "valign=top");
						num2 = 26;
						clsReport.AddCell(clsReport.Bold(clsShared.cLang.GetTranslation("Title")), "valign=top");
						num2 = 27;
						clsReport.AddCell(clsReport.Bold(clsShared.cLang.GetTranslation("Wordcount")), "valign=top");
						num2 = 28;
						clsReport.CloseRow();
						num2 = 29;
						IEnumerator enumerator = pickedIDs.GetEnumerator();
						while (enumerator.MoveNext())
						{
							int iD = Conversions.ToInteger(enumerator.Current);
							num2 = 30;
							clsChapter clsChapter = cProject.get_ChapterByID(iD);
							num2 = 31;
							if (frmPickChapters.WithUnused | !clsChapter.Unused)
							{
								num2 = 32;
								if (clsChapter.SceneCount == 0)
								{
									num2 = 33;
									clsReport.OpenRow();
									num2 = 34;
									clsReport.AddCell(clsChapter.ShortTitle(), "maxwidth=20%");
									num2 = 35;
									clsReport.AddCell("(No scenes)", "colspan=3");
									num2 = 36;
									clsReport.CloseRow();
								}
								num2 = 37;
								int sceneCount = clsChapter.SceneCount;
								for (int i = 1; i <= sceneCount; i++)
								{
									num2 = 38;
									clsScene clsScene = cProject.get_SceneByChID(clsChapter.ID, i);
									num2 = 39;
									if (frmPickChapters.WithUnused | !clsScene.Unused)
									{
										num2 = 40;
										if ((frmPickChapters.VPID <= 0) | (frmPickChapters.VPID == clsScene.ViewPointID))
										{
											num2 = 41;
											if ((Operators.CompareString(frmPickChapters.Tags.Trim(), "", TextCompare: false) == 0) | clsScene.PassesTagFilter(frmPickChapters.Tags))
											{
												num2 = 42;
												if (clsScene.Day_Renamed > num3)
												{
													num2 = 43;
													clsReport.OpenRow();
													num2 = 44;
													clsReport.AddCell(clsReport.Bold("Day " + Conversions.ToString(clsScene.Day_Renamed)));
													num2 = 45;
													clsReport.AddCell("<hr><br />&nbsp;", "colspan=3");
													num2 = 46;
													clsReport.CloseRow();
													num2 = 47;
													num3 = clsScene.Day_Renamed;
												}
												num2 = 48;
												clsReport.OpenRow();
												num2 = 49;
												clsCharacter clsCharacter = cProject.get_CharByID(clsScene.ViewPointID);
												num2 = 50;
												if (Operators.CompareString(left, clsChapter.Title, TextCompare: false) == 0)
												{
													num2 = 51;
													clsReport.AddCell("&nbsp;");
												}
												else
												{
													num2 = 53;
													clsReport.AddCell(clsChapter.ShortTitle(), "maxwidth=20% valign='top'");
													num2 = 54;
													left = clsChapter.Title;
												}
												num2 = 55;
												clsReport.AddCell("Sc " + Conversions.ToString(i) + "<br /><I>" + clsCharacter.Title + "</i>", "valign='top'");
												num2 = 56;
												clsReport.AddCell(clsScene.Title + "<br />&nbsp;");
												num2 = 57;
												clsReport.AddCell(Conversions.ToString(clsScene.Wordcount) + "<br /><i>" + clsReport.FontColour(modVariables.StatusNames[clsScene.Status], modVariables.StatusColours[clsScene.Status]) + "</i>", "align=right valign='top'");
												num2 = 58;
												clsReport.CloseRow();
											}
										}
									}
									num2 = 59;
								}
								num2 = 60;
								if (clsChapter.SceneCount > 0)
								{
									num2 = 61;
									clsReport.OpenRow();
									num2 = 62;
									clsReport.AddCell("&nbsp;", "colspan=4");
									num2 = 63;
									clsReport.CloseRow();
								}
							}
							num2 = 64;
						}
						num2 = 65;
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
						num2 = 66;
						clsShared.cSubs.NormalMouse();
						num2 = 67;
						clsReport.CloseTable();
						num2 = 68;
						clsReport.AddFooter(App.Title);
						num2 = 69;
						clsReport.Show();
						num2 = 70;
						PrintProgressEvent?.Invoke("Printing Complete");
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num4 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_071b: Could not find block for branch target IL_06e7*/;
			}
			if (num4 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
